function Write-Exception
{
    [CmdletBinding()]
    param (
        [parameter(Position=0, ValueFromPipeline=$true)]
        [System.Exception]$Exception,
        [parameter()]
        [switch]$Stack
    )
    
    process 
    {    
        do 
        {
            Write-Warning $Exception.Message
            if ($Stack)
                { Write-Warning $Exception.StackTrace }
            $Exception = $Exception.InnerException
        }
        while ($Exception)
    }
}